# Core Library Compiler Makefile

CC = gcc
CFLAGS = -Wall -O0 -g3 -ggdb -fPIC
LDFLAGS = -shared

# Platform-specific settings
ifeq ($(OS),Windows_NT)
    LIB_SUFFIX = .dll
else
    UNAME_S := $(shell uname -s)
    ifeq ($(UNAME_S),Darwin)
        LIB_SUFFIX = .dylib
    else
        LIB_SUFFIX = .so
    endif
endif

# Library path definition - use the value passed from the top-level Makefile if provided
LIB_DIR ?= ../lib

# Target file name
TARGET = $(LIB_DIR)/core2$(LIB_SUFFIX)
LOCAL_TARGET = core2$(LIB_SUFFIX)

# Source files and object files
SRC = init.c
OBJ = $(SRC:.c=.o)

# Header file directory
INCLUDES = -I../

# Default target
all: $(TARGET)

# Build dynamic library - directly place in LIB_DIR
$(TARGET): $(OBJ)
	@mkdir -p $(LIB_DIR)
	$(CC) $(LDFLAGS) -o $@ $(OBJ)
	@echo "Built core library: $@"

# Compilation rule
%.o: %.c
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

# Clean rule
clean:
	rm -f $(OBJ)
	rm -f $(TARGET)
	rm -f $(LOCAL_TARGET)
	@echo "Core module cleaned"

.PHONY: all clean 